<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\api\model;

use think\Db;
use think\Model;

class GoodsModel extends Model
{
    protected $type = [
    'more' => 'array',
    ];
    //portal_tag
    public function tag_list($where,$field='*') {
    $rel = Db::name("portal_tag")->where($where)->field($field)->select();
       return $rel ;
   }
   public function tagInfo($where,$field='*') {
    $rel = Db::name("portal_tag")->where($where)->field($field)->find();
       return $rel ;
   }

   // 商品查询
   public function goods_list($where,$field='*') {
    $rel = Db::name("portal_post")->where($where)->field($field)->select();
       return $rel ;
   }
    // 商品查询
   public function goods_info($where,$field='*') {
    $rel = Db::name("portal_post")->where($where)->field($field)->find();
    return $rel ;
   }

   // 添加地址
 public function add_address($data) {
    $rel = Db::name("user_address")->insert($data);
       return $rel ;
   }
   // 修改地址
   public function edit_address($where,$data) {
    $rel = Db::name("user_address")->where($where)->update($data);
       return $rel ;
   }
   // 删除地址
    public function del_address($where) {
    $rel = Db::name("user_address")->where($where)->delete();
       return $rel ;
   }
   // 获取配置
   public function get_address($where){
    $rel = Db::name("user_address")->where($where)->order("id DESC")->find();
       return $rel ;

   }
   // 添加订单
    public function add_order($data) {
    $rel = Db::name("order")->insert($data);
       return $rel ;
   }
   // 获取配置
   public function get_config(){
    $rel = Db::name("bankconfig")->find();
       return $rel ;
   }
   public function buy_order($userwhere,$userdata,$goodsdata,$balancedata){
    $transStatus = false;
    Db::startTrans(); //开启事务
      try {
       
        Db::name('user')->where($userwhere)->update($userdata);
   
        Db::name('order')->insert($goodsdata);

        Db::name('user_balance_log')->insert($balancedata);
        $transStatus = true;
        // 提交事务
        Db::commit();
      } catch (\Exception $e) {

        // 回滚事务
        Db::rollback();

      }
      return $transStatus;

   }


}
